<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">

      <panel-group @handleSetLineChartData="handleSetLineChartData" />

      <el-row :gutter="32">
        <el-col :xs="24" :sm="24" :lg="8" class="InformationBar">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>业务提醒</span>
              <el-button style="float: right; padding: 3px 0" type="text">新订单</el-button>
            </div>
            <div style="padding: 20px 20px 0;font-size: 14px;">
              <div v-for="item in orderInfo" class="text item">
                <div>
                  <span>订单号：{{item.id}}</span>
                  <span style="float: right">{{item.createTime}}</span>
                </div>
                <div style="margin-top: 7px;">
                  <span style="margin-right: 20px;">{{item.hosname}}</span>
                  <span style="margin-right: 20px;">{{item.depname}}</span>
                  <span style="margin-right: 20px;">{{item.title}}</span>
                  <span style="float: right">{{item.patientName}}</span>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>

        <el-col :xs="24" :sm="24" :lg="8" class="InformationBar">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>退款通知</span>
              <el-button style="float: right; padding: 3px 0" type="text">查看全部</el-button>
            </div>
            <div style="padding: 20px 20px 0">
              <div v-for="item in refundInfo" class="text item">
                <div>
                  <span>订单号：{{item.orderId}}  </span>
                  <span style="float: right">{{item.createTime}}</span>
                </div>
                <div style="margin-top: 7px;">
                  <span style="margin-right: 20px;">就诊人：{{item.name}}</span>
                  <span>{{item.subject}}</span>
                  <span style="float: right">{{item.totalAmount}}元</span>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>

        <el-col :xs="24" :sm="24" :lg="8" class="InformationBar">
          <el-card class="box-card">
            <div slot="header" class="clearfix" style="text-align: center;">
              <span>公告</span>
            </div>
            <div style="padding: 20px 20px 0">
              <el-table
                :data="officialNews"
                style="width: 100%">
                <el-table-column
                  prop="date"
                  label="日期"
                  align="center">
                </el-table-column>
                <el-table-column
                  prop="theme"
                  label="主题"
                  align="center">
                </el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        尾部
      </el-row>

    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import PanelGroup from './PanelGroup'
import order from '@/api/order'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'Dashboard',
  components: {
    PanelGroup,


  },
  data(){
    return {
      lineChartData: lineChartData.newVisitis,

      //订单信息
      orderInfo: [],

      //退款信息
      refundInfo: [],

      //公告信息
      officialNews: [
        {
        date: '2016-05-02',
        theme: '公司于后天下午讲针对项目展开会议',
        },
        {
        date: '2016-05-04',
        theme: '公司于后天下午讲针对项目展开会议',
        },
        {
        date: '2016-05-01',
        theme: '公司于后天下午讲针对项目展开会议',
        },
        {
        date: '2016-05-03',
        theme: '公司于后天下午讲针对项目展开会议',
        }
      ],
    }
  },
  created() {
    this.getRefundInfo()
    this.findAllOrders()
  },
  methods: {
    handleSetLineChartData(type){
      this.lineChartData = lineChartData[type]
    },

    getRefundInfo(){
      order.getRefundInfo().then(res => {
        this.refundInfo = res.data
      })
    },

    findAllOrders(){
      order.findAllOrders().then(res => {
        this.orderInfo = res.data
      })
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ])
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }

  .box-card {
    height: 317px;
  }

  .box-card .text {
    font-size: 14px;
  }
  /deep/ .el-card__body {
    padding: 0;
  }

  .box-card .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .InformationBar {
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
